<template>
    <div>
        <table class="table">
            <tbody class="table">
                <tr>
                    <td>食谱标题</td>
                    <td>
                        <input type="text" v-model="can.name">
                    </td>
                </tr>
                <tr>
                    <td>食品分类</td>
                    <td>
                        <select v-model="can.tid">
                            <option :value="0">==请选择==</option>
                            <option v-for="d in showdata" :value="d.tid">{{ d.tName }}</option>
                        </select>
                    </td>
                    <td>
                        <input type="button" value="返回康复列表" @click="Add">
                        <input type="button" value="查询" @click="show">
                    </td>
                </tr>
            </tbody>
        </table>
        <table class="table">
            <thead>
                <tr>
                    <td>食谱标题</td>
                    <td>食品分类</td>
                    <td>食品图片</td>
                    <td></td>
                </tr>
            </thead>
            <tbody class="table">
                <tr v-for="s in data">
                    <td>{{s.title}}</td>
                    <td>{{ s.tName }}</td>
                    <td>
                        <img :src="'https://localhost:7220'+s.foodImg" style="height: 60px;width: 60px;">
                    </td>
                    <td></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';

onMounted(() => {
    showdd();
    show();
})

const showdata=ref([{
    "tid": 0,
    "tName": ""
}])

const showdd=()=>{
    axios.get("https://localhost:7220/api/Food/FoodTypes").then(res=>{
        showdata.value=res.data;
    })
}

const can=ref({
    name:'',
    tid:0
})

const data=ref([
{
    "fid": 0,
    "title": "",
    "tid": 0,
    "foodImg": "",
    "tName": ""
  }
])

const show=()=>{
    axios.get("https://localhost:7220/api/Food/GetFood",{params:can.value}).then(res=>{
        data.value=res.data;
    })
}


const router=useRouter();
const Add=()=>{
    router.push({
        path:'/'
    })
}

</script>

<style scoped>

</style>